﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.LIB;
using YJKCodeBase.XmlUtility;

namespace ModelChecking.ModelValidation.ClearHeightCheck
{
	public partial class FloorLevelSelectForm : System.Windows.Forms.Form
	{
		public FloorLevelSelectForm(List<Level> levelList)
		{
			this.InitializeComponent();
			this.m_levelList = levelList;
			this.initListView(levelList);
			this.xmlHelper.LoadXml(this.path, "Root");
		}

		private void initListView(List<Level> levelList)
		{
			for (int i = 0; i < levelList.Count; i++)
			{
				ListViewItem listViewItem = new ListViewItem();
				listViewItem.Text = levelList[i].Name;
				this.listViewFloorLevelList.Items.Add(listViewItem);
			}
			this.listViewFloorLevelList.EndUpdate();
		}

		public List<Level> getSelectedLevelList()
		{
			return this.m_SelectedlevelList;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.listViewFloorLevelList.Items.Count; i++)
			{
				if (this.listViewFloorLevelList.Items[i].Checked)
				{
					this.m_SelectedlevelList.Add(this.m_levelList[i]);
				}
			}
			if (this.m_SelectedlevelList.Count < 1)
			{
				MessageBox.Show("没有选中任何标高信息！");
				return;
			}
			this.SaveDlgData();
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.SaveDlgData();
			base.Close();
		}

		private void btnSelectAll_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.listViewFloorLevelList.Items.Count; i++)
			{
				this.listViewFloorLevelList.Items[i].Checked = true;
			}
		}

		private void btnCancelSelect_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.listViewFloorLevelList.Items.Count; i++)
			{
				this.listViewFloorLevelList.Items[i].Checked = false;
			}
		}

		private void btnReverseSelect_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.listViewFloorLevelList.Items.Count; i++)
			{
				if (this.listViewFloorLevelList.Items[i].Checked)
				{
					this.listViewFloorLevelList.Items[i].Checked = false;
				}
				else
				{
					this.listViewFloorLevelList.Items[i].Checked = true;
				}
			}
		}

		private void SaveDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "CheckTypeSelectForm"));
			this.xmlHelper.SelectNode(Path.Combine("Root", "CheckTypeSelectForm", "Params"));
			this.xmlHelper.SetAttribute("X", base.Location.X.ToString());
			this.xmlHelper.SetAttribute("Y", base.Location.Y.ToString());
			this.xmlHelper.SaveXml("");
		}

		private void LoadDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "CheckTypeSelectForm", "Params"));
			string attribute = this.xmlHelper.GetAttribute("X");
			string attribute2 = this.xmlHelper.GetAttribute("Y");
			if (!string.IsNullOrEmpty(attribute) && !string.IsNullOrEmpty(attribute2))
			{
                base.Location = new System.Drawing.Point(Convert.ToInt32(attribute), Convert.ToInt32(attribute2));
			}
		}

		private void FloorLevelSelectForm_Load(object sender, EventArgs e)
		{
			this.LoadDlgData();
		}

		private const string Root = "Root";

		private const string Node = "CheckTypeSelectForm";

		private const string ChildNode = "Params";

		private const string LocationX = "X";

		private const string LocationY = "Y";

		private List<Level> m_levelList = new List<Level>();

		private List<Level> m_SelectedlevelList = new List<Level>();

		private YJKCodeBase.XmlUtility.XmlHelper xmlHelper = new YJKCodeBase.XmlUtility.XmlHelper();

		private string path = Path.Combine(Product.WorkingLocation, "CheckTypeSelectForm.xml");
	}
}
